/*
   File: clutil.h
 */

#ifndef __CLUTIL__
#define __CLUTIL__

#include <CL/cl.h>
#include <sys/time.h>
#include<sys/resource.h>
#include <sys/types.h>

unsigned initExecution(const unsigned size);

void checkError(const cl_int ciErrNum,  const char* const operation);

void verifyResult(const unsigned size);

char*
readFile(const char*, size_t&);

void init_cl_context();

cl_uint getDeviceCount();

void createCommandQueue();

void compileProgram(const char* const header_file,
                    const char* const kernel_file);


void createKernel(const char* const kernelName);

cl_mem createDeviceBuffer(const cl_mem_flags flags, const size_t size,
                          void* const  hostPtr);

void runKernel(const size_t localWorkSize,
               const size_t globalWorkSize);

void copyToDevice(const cl_mem mem,
                  void* const hostPtr, const unsigned size);


void copyFromDevice(const cl_mem dMem,
                    void* const hostPtr, const unsigned size);

double executionTime();
void allocateHostMemory(const unsigned size);
void allocateDeviceMemory(const unsigned size);
const char* oclErrorString(cl_int error);                          

void printGpuTime();
void buildError();
void cleanup();

extern unsigned useCpu;
extern unsigned useGpu;
extern unsigned blockSize;
extern unsigned fftAlgo;
extern unsigned print;

extern double*  hA;
extern double*  hB;
extern double*  hResult;

extern cl_mem dA;
extern cl_mem dB;
extern cl_mem dResult;

extern cl_context cxContext;
extern cl_program cpProgram;
extern cl_event gpuExecution;
extern cl_event gpuDone;
extern cl_kernel kernel;
extern cl_command_queue commandQueue;

#endif


